package li.webqq.api;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import li.http.Response;
import li.webqq.model.User;
import li.webqq.util.JsonUtil;
import li.webqq.util.MapUtil;

public class GetOnlineBuddies2Response extends Response {
    private List<User> users;

    public List<User> getUsers() {
        if (null == this.users) {
            Map map = (Map) JsonUtil.fromJson(super.getBody());
            List<Map> result = (List<Map>) map.get("result");
            this.users = getUsers(result);
        }
        return this.users;
    }

    private List<User> getUsers(List<Map> result) {
        List<User> users = new ArrayList<User>();
        for (Map each : result) {
            users.add(MapUtil.parse(User.class, each));
        }
        return users;
    }
}